<?php
   // include function files for this application
   require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
   // start session which may be needed later
   // start it now because it must go before headers
   if (!session_id()) { session_start(); }

// We don't want people accessing this page during the con.
/*if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'We are sorry, This page is inaccesibe during the con. Please see the registration desk for assistance registering.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}
*/

// Check to see if registration is open. This is set in conf.inc.php
if ($conf['prereg_status'] = 'closed' || ($_SESSION['admin'] != 't')) {
	do_html_header('Sorry! Convention registration is closed', staysmall, $uny);
	echo 'Convention Pre-registration is not open yet. Please check back later.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

  //If the post vars are not set and the user is not logged in then they must be trying to create a new account with us so display the form with no modification.
  if (empty($_POST) && check_valid_user()) {
  	do_html_header('User Registration Signup Page', staysmall, $uny);
  	
  	$registration_status = get_con_attendance_status($_SESSION['current_attendee_id']);
//  	$result = get_con_attendance_status($_SESSION['current_attendee_id']);
//   	$values = recordproc($result);
//   	extract($values);
      
      	if ( ($registration_status == "approved") || ($registration_status == "pending") ) {
      		echo "You have already submitted your registration for the convention.";
		print_brs(6);
  		do_html_footer(news);
  		exit;
      	}
      	
  	echo "<h2>Registration:</h2>";
	echo "<div class=\"coninfo\">";
	echo "<p>Convention Fees:</p>";
	echo "<ul>";
	echo "<li class=\"infolist\">All Week-end Pass - $25 Pre Registration</li>";
	echo "<li class=\"infolist\">All Week-end Pass - $30 On-Site</li>";
	echo "<li class=\"infolist\">Friday - $15</li>";
	echo "<li class=\"infolist\">Saturday - $20</li>";
	echo "<li class=\"infolist\">Sunday - $20</li>";
	echo "</ul>";
	echo "<em>Please note a $5 processing fee will be charged for all deregistration requests. No refunds will be given on-site.</em>";
  	
  	echo "<h2>Submit Your Registration:</h2>";
  	
  	display_con_registration_form();

	echo "</div>";  	
	print_brs(6);
 	do_html_footer(news);
  	exit;
  }

  	$registration_status = get_con_attendance_status($_SESSION['current_attendee_id']);
//  $result = get_con_attendance_status($_SESSION['current_attendee_id']);
//  $values = recordproc($result);
//  extract($values);
   	
  if ( ($registration_status == "approved") || ($registration_status == "pending") ) {
  	do_html_header('Convention Registration Signup Error', staysmall, $uny);
	echo "You have already submitted your application for the convention.";
	print_brs(6);
	do_html_footer(news);
	exit;
  }
      	
  $attendee_id = $_SESSION['current_attendee_id'];
  if ($gmevents = get_gm_events($attendee_id)) $gmnum = pg_numrows($gmevents);
  if ($cogmevents = get_cogm_events($attendee_id, approved)) $cogmnum = pg_numrows($cogmevents);
  if ($cogmevents = get_cogm_events($_SESSION['current_attendee_id'], pending)) $cogmnumpending = pg_numrows($cogmevents);
  
  $runningevents = $gmnum + $cogmnum;
 
	$reg_status="pending";
	if ($runningevents >= 4 ) $reg_status="approved";
  
  //create short variable names
  $date_select = trim($_POST['date_select']);
	if ($date_select == 'LARP only') {
		$reg_cost = '7.00';
		$date_select = 'saturday';
		// attempt to register
		$reg_result = insert_con_registration($attendee_id, $date_select, 'LARP only', $reg_cost, $reg_status, $_SESSION['attendee_id']);		
		} else {
		$reg_cost = get_badge_cost("$date_select", "general admit pre-reg");
		// attempt to register
		$reg_result = insert_con_registration($attendee_id, $date_select, 'general admit pre-reg', $reg_cost, $reg_status, $_SESSION['attendee_id']);
		}

  if (isset($reg_result) && ($reg_result != 'false')) {
     // provide link to members page
     do_html_header('Convention Registration Signup Successful', staysmall, $uny);
     
     if ($runningevents >= 4 ) {
     	echo "Your registration was successful.  Your fee for the convention is free for since you are running $runningevents events.";
     } elseif (($runningevents + $cogmnumpending) >= 4) {
		echo "<p>It appears the number of events your are GMing and Co-GMing will earn you free admission, but only if the Person in charge approves your Co-GMing of their events. Until that time you wil be unable to pay for your registration and your convention registration will be marked as pending. You can still sign for and pay for events.";
	} else {
     	echo "<p>Your registration was successful.  You need to pay for the convention using PayPal.  Please click the link on the bottom of this page to add it to your cart.</p><br />";
     }

     echo "<p>Your registration is $reg_status.  You may sign up for events.</p><br />";
   	 echo "<p><a href=\"event_list.php\"><img src=\"images/continue-registering.gif\" alt=\"Continue registering for events\" width=\"140\" height=\"40\" border=\"0\"></a> <a href=\"checkout.php\"><img src=\"images/check-out.gif\" alt=\"Check Out\" width=\"140\" height=\"40\" border=\"0\"></a> <a href=\"attendee_home.php\"><img src=\"images/view-schedule.gif\" alt=\"View your schedule\" width=\"140\" height=\"40\" border=\"0\"></a></p>";


  } else {
  	do_html_header('Convention Registration Signup Failed', staysmall, $uny);
        echo "Failure to update your status!";   
  }

  do_html_footer(news);
  // end page

?>